package com.jiazhong.basic.pack0309;

import com.jiazhong.basic.pack0309.Person;

import java.util.ArrayList;
import java.util.Collections;

public class DemoC {

    // 自定义数据类型的查找
    private static void a() {
        ArrayList<Person> list = new ArrayList<>();
        Person p1 = new Person(1, "张三", 23);
        Person p2 = new Person(2, "李四", 17);
        Person p3 = new Person(3, "王五", 29);
        Person p4 = new Person(4, "马六", 21);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        Person p5 = new Person(2, "李四", 17);
        boolean b = list.contains(p5);
        System.out.println(b);
        System.out.println(p2 == p5);
        System.out.println(p2.equals(p5));

    }

    // 自定义数据类型的排序
    private static void b() {
        ArrayList<Person> list = new ArrayList<>();
        Person p1 = new Person(1, "张三", 23);
        Person p2 = new Person(2, "李四", 17);
        Person p3 = new Person(3, "王五", 29);
        Person p4 = new Person(4, "马六", 21);
        Person p5 = new Person(5, "朝气", 24);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        list.add(p5);
        list.forEach(System.out::println);
        // 1. 调用Collections.sort(list);方法
        Collections.sort(list);
        System.out.println("-----------------------");
        list.forEach(System.out::println);
    }

    public static void main(String[] args) {
        b();
    }
}
